#!/usr/bin/python
# -*- coding: UTF-8 -*-

import os
import binascii
import os.path

#工作目录
dir = os.getcwd()

#文件输入
input_file = dir + '/tsl_crc.bin'

input_file_size = os.path.getsize(input_file)

print 'input file size:%d' % input_file_size

f_input = open(input_file, 'r')
f_input_body = f_input.read(input_file_size)
f_input.close()

#文件输出
output_file = dir + '/tsl_crc.c'

f_output = open(output_file, 'w')
f_output.write('#define TSL_ARRAY_LEN (%d)\r\n\r\n' % input_file_size)
f_output.write('static const unsigned char tsl_array[]={')
hex = binascii.hexlify(f_input_body)
for i in range(len(hex)):
    if(i % 32 == 0):
        f_output.write("\r\n")
    if(i % 2 == 0):
        continue
    f_output.write("0x")
    f_output.write(hex[i-1])
    f_output.write(hex[i])
    if(i != len(hex)-1):
        f_output.write(",")
f_output.write('};')
f_output.close()
